#!/usr/bin/env python
#-*-coding: utf-8 -*-
# author: weiyf    data:2015/05/17

def getline(file):
    '''
        getline(file): return filelines (int)
    '''
    return len(open(file).readlines())

def getsize(file):
    '''
        getsize(file): return filezise (int)
    '''
    import os
    return os.path.getsize(file)

def cutfile(file,line=100):
    '''
        cutfile(file,[default line=100])
        if fileline > line, start cutfile
        else return None (str)
    '''
    import os
    
    line = int(line)
    f = open(file).read().split('\n')
    count = len(f)/line
    if count == 0:
        return 'None'
        
    index = 0
    nf = []
    for i in list(range(count)):
        nf += [f[index:index+line]]
        index += line

    nf += [f[index:]]
    loop = zip(nf,list(range(len(nf))))
    os.mkdir(file+'_dir')
    for i in loop:
        data = [m+'\n' for m in i[0]]
        open(file+'_dir/'+file+'.'+str(i[1]),'w').write(''.join(data))

def setlabel(of,label=''):
    '''
        setlabel(file,[default label='']) Nothing to do
        if set label --> setlabel(filename,label='label')
        then create a new file with your label
    '''
    pfile = open(of).read().split('\n')
    data = [m+'    '+label+'\n' for m in pfile]
    with open(of+'_lab','w') as nf:
        nf.write(''.join(data))

if __name__ == '__main__':
    print 'This is a module, please import first'
